package com.badibadi.activity;

import java.util.ArrayList;
import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.badibadi.adapter.AfterLandingMyHomePageAllAdapter_1;
import com.badibadi.infos.Activity_Overview_Model;
import com.badibadi.mytools.Constants;
import com.badibadi.uniclubber.R;
import com.libjph.custom.xlistview.XListView;
import com.libjph.custom.xlistview.XListView.XListViewListener;
//期间的活动
public class Data_During_Activity extends BaseActivity implements
		XListViewListener, OnClickListener {
	private XListView xListView;
	private Button data_during_btn_back, data_during_btn_index;
	private TextView data_during_tital;
	private AfterLandingMyHomePageAllAdapter_1 x1Adapter;
	private List<Activity_Overview_Model> Models;
	private String timedata = null;
	private Handler handler;

	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		goToTheTitle();
		setContentView(R.layout.data_during_actlist);
		timedata = getIntent().getStringExtra("日期");
		init();
		AddData();
	}

	private void init() {
		handler = new Handler();
		xListView = (XListView) findViewById(R.id.data_during_xListView1);
		data_during_btn_back = (Button) findViewById(R.id.data_during_btn_back);
		data_during_btn_index = (Button) findViewById(R.id.data_during_btn_index);
		data_during_tital = (TextView) findViewById(R.id.data_during_tital);
		// xListView.setDividerHeight(10);
		xListView.setPadding(10, 0, 10, 10);
		xListView.setXListViewListener(this);
		xListView.setPullLoadEnable(true);
		xListView.setPullRefreshEnable(false);
		data_during_btn_back.setOnClickListener(this);
		data_during_btn_index.setOnClickListener(this);
		Models = new ArrayList<Activity_Overview_Model>();
		String t = null;
		if (timedata != null) {
			t = String.format(getResources().getString(R.string.XXXXActivity),
					timedata);
		} else {
			t = String.format(getResources().getString(R.string.XXXXActivity),
					"12.01.01");
		}
		data_during_tital.setText(t);
	}

	protected void onLoad() {
		// TODO Auto-generated method stub
		xListView.stopRefresh();
		xListView.stopLoadMore();
	}

	private void AddData() {
		for (int i = 0; i < Constants.temp_num.size(); i++) {
			Models.add(Constants.overview_Models.get(Constants.temp_num.get(i)));
		}
//		   ("数据的大小是:" + Models.size());
		x1Adapter = new AfterLandingMyHomePageAllAdapter_1(Models,
				getApplicationContext(), 1, 0.0, 0.0,"2");
		
		xListView.setAdapter(x1Adapter);
	}

	@Override
	public void onClick(View arg0) {
		switch (arg0.getId()) {
		case R.id.data_during_btn_index:
			Intent intent = new Intent(Data_During_Activity.this,
					IndexActivity.class);
			startActivity(intent);
			break;
		case R.id.data_during_btn_back:
			this.finish();
			break;

		default:
			break;
		}
	}

	@Override
	public void onListViewRefresh() {
		// TODO Auto-generated method stub
		handler.postDelayed(new Runnable() {

			@Override
			public void run() {
				onLoad();
			}
		}, 2000);

	}

	@Override
	public void onListViewLoadMore() {
		// TODO Auto-generated method stub
		handler.postDelayed(new Runnable() {

			@Override
			public void run() {
				onLoad();
			}
		}, 2000);
	}
}
